<?php

// +----------------------------------------------------------------------------------------------+
// | Funktion                                                                                	  |
// | Argumente                                                                    				  |
// | Returnwert                                                                                   |
// |			   							         											  |
// |                                                                                              |
// | Beschreibung                                                                                 |
// |                                                                                              |
// | Version  Datum       Beschreibung                                                  Autor     |
// | -------  ----------  ------------                                                  -----     |
// | V1.00    19.06.2009  erstellt                                                      dbru      |
// +----------------------------------------------------------------------------------------------+
function getPageContentOfPosition($position,$userRight,$type,$name = null){

	if ($type =='p'){
		$result = DBSelect("p.pageID,p.pagePath,p.pageState","cms_page_rights AS cpr, cms_page AS p","cpr.rightID = {$userRight} AND cpr.pageID = p.pageID AND shortSign ='{$name}' ","LIMIT 1");
		if(mysql_num_rows($result) > 0){
			ob_start();
			while($row = mysql_fetch_object($result)){
				if($row->pageState != 1){
					include $row->pagePath;
				}else{
					ob_end_clean();
					mysql_free_result($result);
					return -4;
				}
			}
			$content = ob_get_contents();
			ob_end_clean();
			mysql_free_result($result);
			return $content;
		}else{
			mysql_free_result($result);
			return -5;
		}
	}else{
		$result = DBSelect("p.pageID,p.pagePath,p.pageState","cms_page_rights AS cpr, cms_page AS p","cpr.rightID = {$userRight} AND cpr.pageID = p.pageID AND pageType ='{$type}' AND pagePosition = '".substr($position,0,1)."' "," ORDER BY p.orderPos ASC");
		if(mysql_num_rows($result) > 0){
			ob_start();
			while($row = mysql_fetch_object($result)){
				if($row->pageState != 1){
					include $row->pagePath;
				}
			}
			$content = ob_get_contents();
			ob_end_clean();
			mysql_free_result($result);
			return $content;
		}else{
			return "";
		}
	}


}

// +----------------------------------------------------------------------------------------------+
// | Funktion                                                                                	  |
// | Argumente                                                                    				  |
// | Returnwert                                                                                   |
// |			   							         											  |
// |                                                                                              |
// | Beschreibung                                                                                 |
// |                                                                                              |
// | Version  Datum       Beschreibung                                                  Autor     |
// | -------  ----------  ------------                                                  -----     |
// | V1.00    19.06.2009  erstellt                                                      dbru      |
// +----------------------------------------------------------------------------------------------+
function getPageContentOfPositionTitle($pageShortSign) {
	$result = DBSelectToArray("*","cms_page"," shortSign ='{$pageShortSign}' LIMIT 1");

	if(!empty($result)){
		return $result['pageTitle'];
	}else{
		return "Diese Seite wurde nicht gefunden";
	}
}

// +----------------------------------------------------------------------------------------------+
// | Funktion                                                                                	  |
// | Argumente                                                                    				  |
// | Returnwert                                                                                   |
// |			   							         											  |
// |                                                                                              |
// | Beschreibung                                                                                 |
// |                                                                                              |
// | Version  Datum       Beschreibung                                                  Autor     |
// | -------  ----------  ------------                                                  -----     |
// | V1.00    19.06.2009  erstellt                                                      dbru      |
// +----------------------------------------------------------------------------------------------+
function getPageLinksWithRights($userRight) {
	$links = array();

	$result = DBSelect("p.shortSign,p.pageState,p.pageTitle","cms_page_rights AS cpr, cms_page AS p","((cpr.rightID > 0 AND cpr.rightID < 3 AND cpr.rightID = {$userRight}) OR ( {$userRight} > 2 AND cpr.rightID = {$userRight})) AND cpr.pageID = p.pageID AND p.pageType = 'p' AND p.isAdmin = 'f'","ORDER BY p.orderPos ASC");
	if(mysql_num_rows($result) > 0){
		while($row = mysql_fetch_object($result)){
			if($row->pageState != 1){
				$links[] = "<a href='{$_SERVER['PHP_SELF']}?currentPage={$row->shortSign}'>{$row->pageTitle}</a>";
			}
		}
	}
	mysql_free_result($result);
	return $links;
}

// +----------------------------------------------------------------------------------------------+
// | Funktion                                                                                	  |
// | Argumente                                                                    				  |
// | Returnwert                                                                                   |
// |			   							         											  |
// |                                                                                              |
// | Beschreibung                                                                                 |
// |                                                                                              |
// | Version  Datum       Beschreibung                                                  Autor     |
// | -------  ----------  ------------                                                  -----     |
// | V1.00    19.06.2009  erstellt                                                      dbru      |
// +----------------------------------------------------------------------------------------------+
function getAdminPageLinksWithRights($userRight) {
	$links = array();

	$result = DBSelect("p.shortSign,p.pageState,p.pageTitle","cms_page_rights AS cpr, cms_page AS p","cpr.rightID = {$userRight} AND cpr.pageID = p.pageID AND p.pageType = 'p' AND p.isAdmin = 't'","ORDER BY p.orderPos ASC");
	if(mysql_num_rows($result) > 0){
		while($row = mysql_fetch_object($result)){
			if($row->pageState != 1){
				$links[] = "<a href='{$_SERVER['PHP_SELF']}?currentPage={$row->shortSign}'>{$row->pageTitle}</a>";
			}
		}
	}
	mysql_free_result($result);
	return $links;
}

// +----------------------------------------------------------------------------------------------+
// | Funktion                                                                                	  |
// | Argumente                                                                    				  |
// | Returnwert                                                                                   |
// |			   							         											  |
// |                                                                                              |
// | Beschreibung                                                                                 |
// |                                                                                              |
// | Version  Datum       Beschreibung                                                  Autor     |
// | -------  ----------  ------------                                                  -----     |
// | V1.00    19.06.2009  erstellt                                                      dbru      |
// +----------------------------------------------------------------------------------------------+
function getCSSOfPage($currentPage) {
	
	$result = DBSelectToArray("*","cms_page"," shortSign ='{$currentPage}' LIMIT 1");

	if(!empty($result) && $result['addCSS'] != '' && $result['addCSS'] != ' '){
		return "<link rel='stylesheet' type='text/css' href='{$result['addCSS']}'>";
	}else{
		return "";
	}
}

?>